const log = require('../util/log'),
    config = require('../util/config'),
    logger = require('log4js').getLogger()

module.exports = (req, res) => {
    require('../util/service').handlePost(req, res, async (reqObj, resolve) => {
        if (config.domain == '') {
            if (!reqObj.codeText) {
                resolve({
                    result: -1,
                    msg: '缺少codeText'
                })
                return
            }
            if (!reqObj.codeRequestId) {
                resolve({
                    result: -1,
                    msg: '缺少codeRequestId'
                })
                return
            }
            require('../mng/chromeMng').submitCode(reqObj).then(result => {
                resolve({
                    result: 1
                })
            })
        } else if (config.domain == 'zoro.site') {
            if (!req.session.chromeServer) {
                resolve({
                    result: -1,
                    msg: '系统错误'
                })
                return
            }
            require('../util/getHtml')({
                url: req.session.chromeServer + 'submitFanliCode.do',
                data: JSON.stringify(reqObj)
            }).then(result => {
                logger.debug('[' + __filename + ':' + __line + ']', result)
                resolve(JSON.parse(result))
            }, result => {
                logger.error('[' + __filename + ':' + __line + ']', result)
                resolve({
                    result: -1,
                    msg: '系统错误'
                })
            })
        }
    })
}
